//
//  MYBaseViewController.swift
//  MYWeiBo
//
//  Created by apple on 16/5/10.
//  Copyright © 2016年 YanMo. All rights reserved.
//

import UIKit

class MYBaseViewController: UITableViewController {
    
  //根据用户显示不同界面
    var userLogin:Bool = MYUserAccountModel.sharedInstance.isUserLogin
    override func loadView() {
        if userLogin{
           super.loadView()
        }else{
       
            //把view界面给换成自己的
            view = visitorView
            //成为它的代理
            visitorView.delegate = self
            if self is MYHomeViewController
            {
                visitorView.startRotationAnimation()
            }else if self is MYMessageViewController
            {
                visitorView.setupVistorInfo("visitordiscover_image_message", message: "登录后，别人评论你的微博，发给你的消息，都会在这里收到通知")
            
            }else if self is MYDiscoveryViewController
            {
                visitorView.setupVistorInfo("visitordiscover_image_message", message: "登录后，最新、最热微博尽在掌握，不再会与实事潮流擦肩而过")
                
            }else if self is MYProfileViewController
            {
                visitorView.setupVistorInfo("visitordiscover_image_profile", message:"登录后，你的微博、相册、个人资料会显示在这里，展示给别人")
            
            }
            
            //设置导航栏按钮
            self.navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "vistorViewDidClickRegister")
            self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "vistorViewDidClickLogin")

            
        }
    }
    //懒加载
    private lazy var visitorView:MYVisitorView = MYVisitorView()
}

//遵守协议，实现代理
extension MYBaseViewController:MYVisitorViewDelegate {
    //实现代理
    func vistorViewDidClickRegister() {
       
//        print( __FUNCTION__)
        
    }
    func vistorViewDidClickLogin() {
//        print( __FUNCTION__)
        //model出控制器
        let oauthVC = MYOauthViewController()
        let nav = UINavigationController(rootViewController: oauthVC)
        self.presentViewController(nav, animated: true, completion: nil)

    }
}















